package cn.source.zk.domain.dto;

import cn.source.zk.domain.entity.DBIhra;
import cn.source.zk.domain.entity.DBIhrb;
import cn.source.zk.domain.entity.DBIhrc;
import lombok.Data;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @author shiqi
 * @create 2025-04-27 11:19
 */
@Data
public class DBIhrDTO {

    private LocalDateTime timedate;

    private Map<String, Object> fields = new HashMap<String, Object>();

    //构建db_ihra表
    public void buildToIhra(DBIhra dbIhra, Map<Integer,String> fieldNames){
        if(dbIhra != null){
            this.timedate = dbIhra.getTimedate();
            if(fieldNames != null && !fieldNames.isEmpty()){
                fieldNames.forEach((k,v)->{
                    try{
                        Field field = DBIhra.class.getDeclaredField(v);
                        field.setAccessible(true);
                        fields.put("a_"+v, field.get(dbIhra));
                    } catch (Exception e){

                    }
                });
                // for (String fieldName : fieldNames) {
                //     try{
                //         Field field = DBIhra.class.getDeclaredField(fieldName);
                //         field.setAccessible(true);
                //         fields.put("a_"+fieldName, field.get(dbIhra));
                //     } catch (Exception e){
                //
                //     }
                // }

            }
        }
    }

    public void buildToIhrb(DBIhrb dbIhrb, Map<Integer,String> fieldNames){
        if(dbIhrb != null){
            this.timedate = dbIhrb.getTimedate();
            if(fieldNames != null && !fieldNames.isEmpty()){
                fieldNames.forEach((k,v)->{
                    try{
                        Field field = DBIhrb.class.getDeclaredField(v);
                        field.setAccessible(true);
                        fields.put("b_"+v, field.get(dbIhrb));
                    } catch (Exception e){

                    }
                });
                // for (String fieldName : fieldNames) {
                //     try{
                //         Field field = DBIhrb.class.getDeclaredField(fieldName);
                //         field.setAccessible(true);
                //         fields.put("a_"+fieldName, field.get(dbIhrb));
                //     } catch (Exception e){
                //
                //     }
                // }

            }
        }
    }

    public void buildToIhrc(DBIhrc dbIhrc, Map<Integer,String> fieldNames){
        if(dbIhrc != null){
            this.timedate = dbIhrc.getTimedate();
            if(fieldNames != null && !fieldNames.isEmpty()){

                fieldNames.forEach((k,v)->{
                    try{
                        Field field = DBIhrc.class.getDeclaredField(v);
                        field.setAccessible(true);
                        fields.put("c_"+v, field.get(dbIhrc));
                    } catch (Exception e){

                    }
                });

                // for (String fieldName : fieldNames) {
                //     try{
                //         Field field = DBIhrc.class.getDeclaredField(fieldName);
                //         field.setAccessible(true);
                //         fields.put("a_"+fieldName, field.get(dbIhrc));
                //     } catch (Exception e){
                //
                //     }
                // }

            }
        }
    }

}
